package qlsl.androiddesign.http.service.subservice;

import java.util.HashMap;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import qlsl.androiddesign.constant.MessageConstant;
import qlsl.androiddesign.constant.WhatConstant;
import qlsl.androiddesign.entity.commonentity.Pager;
import qlsl.androiddesign.entity.otherentity.JiFen;
import qlsl.androiddesign.entity.otherentity.PostingsGoods;
import qlsl.androiddesign.handler.subhandler.HttpHandler;
import qlsl.androiddesign.http.HttpListener;
import qlsl.androiddesign.http.service.baseservice.BaseService;
import qlsl.androiddesign.http.xutils.HttpProtocol;
import qlsl.androiddesign.method.UserMethod;
import qlsl.androiddesign.thread.HandlerThread;
import qlsl.androiddesign.util.commonutil.PagerUtils;
import qlsl.androiddesign.util.runfeng.ThreadManager;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 兑换记录模块 <br/>
 * 
 */
public class RecorderService extends BaseService {

	private static String className = getClassName(RecorderService.class);

	public static void queryRecorder(final int page,
			final FunctionView<?> functionView, final HttpListener listener) {
		final HttpHandler handler = getHandler(functionView, listener,
				className, "queryRecorder");

		ThreadManager.getThreadPool(className, "queryRecorder").execute(
				new Runnable() {

					@Override
					public void run() {
						HttpProtocol protocol = new HttpProtocol();
						try {
							JSONObject jo = protocol
									.setMethod("coshingloglist").post();
							if (isDataInvalid(jo, handler, protocol)) {
								return;
							}
							//
							HashMap<String, Object> map = new HashMap<String, Object>();

							List<JiFen> list = JSONArray.parseArray(
									jo.getString("rows"), JiFen.class);

							Pager pager = PagerUtils.createPager(page, jo);
							map.put("list", list);
							map.put("pager", pager);

							handler.sendMessage(protocol,
									WhatConstant.WHAT_NET_DATA_SUCCESS, map);
						} catch (Exception e) {
							e.printStackTrace();
							handler.sendMessage(protocol,
									WhatConstant.WHAT_EXCEPITON, e);
						}
					}
				});
	}
}
